<?php
    include_once("Models/NguoiDung.php");
    if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
        $nd = new NguoiDung();
        $nd->setMaQuyen($_SESSION['nmaquyen']);
        $nd->setMaSo($_SESSION['nmaso']);
		$matkhaucu = md5(trim($_POST['txtmatkhaucu']));
		$nd->setMatKhau($matkhaucu);
		if($nd->kiemTra()!=0)
		{
			$matkhaumoi = md5(trim($_POST['txtmatkhaumoi1']));
			$nd->setMatKhau($matkhaumoi);
			if ($nd->suaNguoiDung() > 0){
				echo "<script language=javascript> alert('Đổi thành công!'); </script>";
				include_once("Controls/ThoatController.php");
			}
			else{
				 echo "<script language=javascript> alert('Không đổi được!'); </script>";
				include_once('Views/Doimatkhau.php');
			}
		}
		else
		{
			echo "<script language=javascript> alert('Nhập sai mật khẩu cũ!'); </script>";
			include_once('Views/Doimatkhau.php');
		}
    }                                
    else include_once('Views/Doimatkhau.php');
?>
